/**
 *@auther: tang
 @Date: 2020-11-14
 *Project: group-booking-shop-manage-system
 */
import React from "react"
import {Button, Form, Input, Row,Col,message} from 'antd';
import Req from "../../../../api"

class UpdateAdmInfo extends React.Component {
    constructor(props) {
        super(props);
        this.admForm = React.createRef();
    }
    onFinish(data){
        console.log(data);
        Req.uptAdmInfo({
            username:data.username,
            password:data.userPwd,
            id:this.props.initInfo.adm_id
        }).then(res=>{
            console.log(res);
                message.success(`修改成功,已修改名为${data.username}的管理员`);
                //重置表单
                this.admForm.current.resetFields();
                // console.log(this.state.tabHNode)
            this.props.closeModal();
        //    关闭模态框
        }).catch(err=>{
            console.log(err)
        })

    }
    componentWillMount() {
        console.log({username:this.props.initInfo.adm_username,password:this.props.initInfo.adm_password})
    }

    render() {
        return (
            <div>
                <Form
                    ref={this.admForm}
                    name="basic"
                    initialValues={{username:this.props.initInfo.adm_username,userPwd:this.props.initInfo.adm_password}}
                    onFinish={this.onFinish.bind(this)}
                    hideRequiredMark
                    labelCol={{
                        span:4
                    }}
                    wrapperCol={{
                        span:10
                    }}
                >
                    <Form.Item
                        label="用户名"
                        name="username"
                        rules={[
                            {
                                required: true,
                                message: '请输入用户名',
                            },
                        ]}
                    >
                        <Input type="text"/>
                    </Form.Item>

                    <Form.Item
                        label="密码"
                        name="userPwd"
                        rules={[
                            {
                                required: true,
                                message: '请输入密码'
                            },
                        ]}
                    >
                        <Input />
                    </Form.Item>
                    <Form.Item>
                        <Row>
                            <Col span={12}></Col>
                            <Col span={8}>
                                <Button type="primary" htmlType="submit">
                                    提交
                                </Button>
                            </Col>

                        </Row>

                    </Form.Item>
                </Form>

            </div>
        )
    }
}

export {UpdateAdmInfo as default}
